{% extends "double.html" %}
{% block title %}{{ page_title }}{% endblock %}
{% block styles %}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}styles/tweetdetail.css">
{% endblock %}
{% block scripts %}
    <script type="text/javascript">
        $(document).ready(function(){
            var sectionheight = $('section').height();
            $('aside').height(sectionheight);


            $('.reply').toggle(function(){
                $('.replyform').slideDown('slow');
            }, function(){
                $('.replyform').slideUp('slow');
            })
        })
    </script>
{% endblock %}
{% block main %}  
<div class="tweetdetail">
    <div class="avatar50">
        <img src="{{ MEDIA_URL }}avatar/50/{{ detailtweet.user.profile.avatar }}">
    </div>

    <div class="tweetgroup">
        <div class="currenttweet">
            <div class="tweetwarp">
                <a class="tweetuser" href="{{ detailtweet.user.profile.get_user_index_url }}">@{{ detailtweet.user.username }}: </a>
                <div class="tweetcontent">{{ detailtweet.message|urlize }}</div>
            </div>
        </div>
        {% if detailtweet.orginmessage %}
            <div class="origntweet">
                <a class="tweetuser" href="{{ detailtweet.orginmessage.user.get_user_index_url }}">@{{ detailtweet.orginmessage.user.username }}: </a>
                <div class="retweetcontent">{{ detailtweet.orginmessage|urlize }}</div>
                <em class="readdtime">{{ detailtweet.orginmessage.addtime_format_admin }}</em>
            </div>
        {% endif %}
        <div class="clear"></div>
    </div>

    <div class="addtime">
        <em>{{ detailtweet.addtime|timesince}} 前</em>
    </div>
    <div class="operating">
        <a class="reply" href="javascript:;">评论({{ replytweets.count }})</a>
        {% if user in detailtweet.favorite.favuser.all  %}
            <a href="{% url mblog_favorite_del user.username  detailtweet.favorite.id %}">取消收藏({{ detailtweet.favorite.favuser.count }})</a>
        {% else %}
            <a href="{% url mblog_favorite_add user.username  detailtweet.id %}">收藏({{ detailtweet.favorite.favuser.count|default:'0' }})</a>
        {% endif %}
    </div> 

    <div class="replyform">
        <form method="post" action=".">
            {% csrf_token %}
            {{ form.as_p }}
            <input type="submit" class="replysubmit" value="回复">
        </form>
    </div>
    <div class="replytweets">
        <ul>
            {% if replytweets %}
                {% for retweet in replytweets %}
                    <li>
                        <div class="avatar50">
                            <img src="{{ MEDIA_URL }}avatar/50/{{ retweet.replyer.profile.avatar }}">
                        </div>
                        <div><a href="{{ retweet.replyer.get_user_index_url }}">@ {{ retweet.replyer.username }}</a></div>
                        <div class="tweet">
                            <p>{{ retweet.replytweet|urlize }}</p>
                            <em>{{ retweet.addtime|timesince }} 前</em>
                        </div>
                        {% if retweet.replyer.username == user.username or retweet.subject.user.username == user.username %}
                        <div class="operating">
                            <a href="{% url mblog_replytweet_del retweet.replyer retweet.subject.user.username retweet.id %}">删除</a>
                        </div>
                        {% endif %}
                        <div class="clear"></div>
                    </li>
                {% endfor %}
            {% endif %}
        </ul>
    </div>
    <div class="clear"></div>
</div>
{% endblock %}